package com.cbn.ibcp.web.smp.domain.superEntity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.cbn.ibcp.web.smp.valid.Update;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.cbn.ibcp.common.annotation.Excel;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
 * 实体父类
 *
 */
@Setter
@Getter
public class SuperEntity<T extends Model<?>> extends Model<T> {

    /**
     * 主键ID
     */
    @TableId
    @NotNull(message = "主键ID不可为空", groups = Update.class)
    private Long id;

    @TableField(fill = FieldFill.DEFAULT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH-mm-ss")
    @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date createdTime;

    @TableField(fill = FieldFill.DEFAULT)
    private Long createdBy;

    @TableField(exist = false)
    @Excel(name = "创建人姓名")
    private String createdByName;

    @TableField(fill = FieldFill.DEFAULT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH-mm-ss")
    @Excel(name = "修改时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date updatedTime;

    @TableField(fill = FieldFill.DEFAULT)
    private Long updatedBy;

    @TableField(exist = false)
    @Excel(name = "修改人姓名")
    private String updatedByName;

    @TableField(fill = FieldFill.DEFAULT)
    @JsonIgnore
    private Long delFlag;

    /** 请求参数 */
    @TableField(exist = false)
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private Map<String, Object> params = new HashMap<>();

    /** 是否更新已经存在的数据 */
    @TableField(exist = false)
    private Boolean updateSupport;

    @Override
    protected Serializable pkVal() {
        return this.id;
    }

    /** 新增自定义请求参数 */
    public void addParams(String key, Object value) {
        params.put(key,value);
    }
}
